
package com.jf.cloud.multishop.listener;

import cn.hutool.core.collection.CollUtil;
import com.jf.cloud.api.distribution.bo.DistributionNotifyOrderAndShopBO;
import com.jf.cloud.api.multishop.bo.ShopWalletBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.multishop.service.ShopWalletService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 分销通知修改店铺钱包
 * @author zz
 * @date 2021-08-19 13:29:55
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.DISTRIBUTION_NOTIFY_ORDER_SHOP_TOPIC, consumerGroup = RocketMqConstant.DISTRIBUTION_NOTIFY_SHOP_GROUP)
public class DistributionNotifyShopConsumer implements RocketMQListener<DistributionNotifyOrderAndShopBO> {
    private static final Logger LOG = LoggerFactory.getLogger(DistributionNotifyShopConsumer.class);

    @Autowired
    private ShopWalletService shopWalletService;

    @Override
    public void onMessage(DistributionNotifyOrderAndShopBO message) {
        List<ShopWalletBO> shopWalletBOList = message.getShopWalletBOList();
        if (CollUtil.isEmpty(shopWalletBOList)) {
            return;
        }
        LOG.info("分销金额计算完成后,分销通知修改店铺钱包回调开始... message: " + Json.toJsonString(shopWalletBOList));
        shopWalletService.updateByDistributionAmount(shopWalletBOList);
    }

}
